{include file="public/head" /}
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">权限管理</a>
            <a href="">角色管理</a>
            <a>
              <cite>角色列表</cite></a>
          </span>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5"></form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('编辑','../Role/add', 1080, 650)">
                        <i class="layui-icon"></i>增加
                    </button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form" id="pagetab">
                        <thead>
                        <tr>
                            <th style="width: 100px;">ID</th>
                            <th>角色名称</th>
                            <th>昵称</th>
                            <th class="{:adminAuthCheck('/Role/status',$routeArr)}">状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody>
                        {volist name="res" id="v"}
                        <tr>
                            <td>{$v.id}</td>
                            <td>{$v.role_name}</td>
                            <td>{$v.nickname}</td>
                            <td class="{:adminAuthCheck('/Role/status',$routeArr)}">
                                <input type="checkbox" lay-filter="switchID" switch_id="{$v['id']}"
                                       name="work_status" lay-text="开启|停用"  lay-skin="switch"
                                       {if condition="$v.status eq '1'"} checked="checked" {/if} >
                            </td>
                            <td class="td-manage">
                                <span onclick="xadmin.open('编辑','../Role/update/id/{$v.id}', 1080, 650)"
                                      class="layui-btn layui-btn-group layui-btn-mini {:adminAuthCheck('/Role/update',$routeArr)}">编辑</span>
                                <span onclick="member_del(this,{$v.id})" class="layui-btn layui-btn-danger layui-btn-mini {:adminAuthCheck('/Role/delete',$routeArr)}">删除</span>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page" id="page"></div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form', 'laypage'], function(){
        var laydate = layui.laydate;
        var laypage = layui.laypage;
        var form = layui.form;
        var url = '{:url("../Role/index")}'+'?{$query}';

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });

        //执行一个laypage实例
        laypage.render({
            elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
            ,count:'{$count}'//数据总数，从服务端得到
            ,limit :'{$pageTotal}'
            ,curr:'{$curr}'
            ,jump: function(obj, first){
                if(!first){ //一定要加此判断，否则初始时会无限刷新
                    location.href = url+'&page='+obj.curr;
                }
            }
        });

        // 开启|关闭
        form.on('switch(switchID)',function(data){
            //开关是否开启，true或者false
            var checked =  data.elem.checked;
            //获取所需属性值
            var switch_id =  data.elem.attributes['switch_id'].nodeValue;
            var status = 0;
            if(checked == true){
                status = 1;
            }
            $.ajax({
                type: "POST",
                url: "{:getUrl()}Role/status",
                data: {id:switch_id,status:status},
                dataType: "json",
                success: function(res){
                    if(res.code == 200){
                        // 修改成功
                        if(checked == true){
                            layer.msg('已开启!',{icon: 6,time:1000});
                        }else{
                            layer.msg('已停用!',{icon: 5,time:1000});
                        }
                    }else{
                        // 修改失败
                        layer.msg(res.msg,{icon: 5,time:1000});
                    }
                }
            });

        })

    });

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index)
        {
            //发异步删除数据
            $.ajax({
                type: "POST",
                url: "{:getUrl()}Role/delete",
                data: {id:id},
                dataType: "json",
                success: function(data){
                    if(data.code == 200) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000},function(){
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon: 5,time:1000},function(){
                            parent.location.reload();
                        });
                    }
                }
            });

        });
    }
    function delAll(argument)
    {
        var data = tableCheck.getData();
        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</html>
